package components{
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import model.EventTDir;
	import model.siw.ET;
	import model.siw.OP;
	import model.siw.Rule;
	import model.siw.SIW;
	import model.siw.Service;
	
	import mx.controls.Button;
	import mx.core.Application;
	
	import util.ConfigUtil;
	import util.Constants;
	import util.HtmlWindow;
	import util.IFrame;
	import util.Utils;
	
	public class MediatorButton extends Button{
		
		private var _app:Application;
		
		private var _config:ConfigUtil;
		
		private var _win:HtmlWindow;
		
		private var _frame:IFrame;
		
		public function MediatorButton(){
			this.addEventListener(MouseEvent.CLICK, clickDispose);
		}
		
		public function clickDispose(event:Event):void{
			
			if(event.target.label=="触发配置"){
				
				var processId:String=config.getProcessId();
				var activityId:String=config.getActivityId();
				var activityName:String=config.getActivityName()
				var eventT:EventTDir=config.getEventT();
				var uuid:String=Utils.genUUID();
				var url:String=Constants.DRIVER_PATH+Constants.LISTENEROBJ+activityName+"&"+Constants.TRIGGEREDEVENT+eventT.id+"&"+Constants.OBJTYPE+Constants.ACTIVITY_OBJTYPE+"&"+Constants.TYPE+Constants.TRIGGER_TYPE+"&"+Constants.OP+Constants.NEW_OP+"&"+Constants.PROCESSID+processId+"&"+Constants.ACTID+activityId+"&uuid="+uuid;
				frame.source=url;
				//frame.visible=true;
				win.title="触发配置窗口";
				win.setVisible(true);
				
				var rule:Rule=new Rule();
				rule.id=uuid;
				rule.type="etr";
				
				var service:Service=new Service();
				service.id=config.getProcessId();
				service.name=config.getProcessName();
				
				rule.service=service;
				
				var op:OP=new OP();
				op.id=config.getActivityId();
				op.name=config.getActivityName();
				
				rule.op=op;
				
				var et:ET=new ET();
				
				et.id=config.getEventT().id;
				et.topic=config.getEventT().name;
				
				rule.et=et;
				
				var siw:SIW=SIW.createInstance();
				
				siw.rules.addItem(rule);
			}
			
			if(event.target.label=="监听配置"){
				frame.source="http://www.baidu.com/";
				//frame.visible=true;
				win.title="监听配置窗口";
				win.setVisible(true);
				
		 		/* PopUpManager.addPopUp(win, app, true);
				PopUpManager.centerPopUp(win);
			    PopUpManager.bringToFront(win);	   */
			    	
			}
			
		}
		
		public function get app():Application{
			return this._app;
		}
		
		public function set app(v:Application):void{
			this._app=v;
		}
		
		public function get win():HtmlWindow{
			return this._win;
		}
		
		public function set win(v:HtmlWindow):void{
			this._win=v;
		}
		
		public function get frame():IFrame{
			return this._frame;
		}
		
		public function set frame(v:IFrame):void{
			this._frame=v;
		}

		public function get config():ConfigUtil{
			return this._config;
		}
		
		public function set config(v:ConfigUtil):void{
			this._config=v;
		}
	}
}